<?php

namespace App\Http\Controllers\View\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Facades\Services\CaseService;
use App\Facades\Services\CaseTypeService;
use App\Facades\Services\AddressService;
use App\Facades\Services\LevelService;

class CaseController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
    	$cases = CaseService::getAll($request);

        // dd($cases->toArray());
    	$caseTypes = CaseTypeService::getAll();

    	$provinces = AddressService::getAllProvince();

    	$conditions = $request->all();

        return view('pages.case.list',[
        	'cases' => $cases,
        	'caseTypes' => $caseTypes,
        	'provinces' => $provinces,
        	'conditions' => $conditions
        	]);
    }

    public function create(Request $request){

        // dd(LevelService::getAll()->toArray());
        return view('pages.case.create',[
                'caseTypes' => CaseTypeService::getAll(),
                'provinces' => AddressService::getAllProvince(),
                'levels' => LevelService::getAll(),
            ]);

    }

    public function update(Request $request){

        $case = CaseService::getById($request);

        // dd($case->toArray());

        $citys = AddressService::getAllCityByProvinceId($case);

        return view('pages.case.update',[
                'citys' => $citys,
                'case' => $case,
                'caseTypes' => CaseTypeService::getAll(),
                'provinces' => AddressService::getAllProvince(),
                'levels' => LevelService::getAll(),
            ]);
    }
}
